package org.codehaus.janino.util.resource;

import j2me.util.collections.Collection;
import j2me.util.collections.Iterator;
import org.codehaus.janino.Resource;

/**
 * A {@link org.codehaus.janino.util.resource.ResourceFinder} that finds its
 * resources through a collection of other {@link org.codehaus.janino.util.resource.ResourceFinder}s.
 */
public class MultiResourceFinder extends ResourceFinder {

    private final Collection resourceFinders; // One for each entry

    /**
     * @param resourceFinders The entries of the "path"
     */
    public MultiResourceFinder(Collection resourceFinders) {
        this.resourceFinders = resourceFinders;
    }

    // Implement ResourceFinder.
    public Resource findResource(String resourceName) {
        for (Iterator it = this.resourceFinders.iterator(); it.hasNext();) {
            ResourceFinder rf = (ResourceFinder) it.next();
            Resource resource = rf.findResource(resourceName);
            
            if (resource != null) {
                return resource;
            }
        }
        
        return null;
    }
}
